<?php
namespace app\zhonghang\controller;
use think\Controller;
use think\Request;
use think\Db;
use think\Session;
use think\Lang;
use think\Cookie;

class Collection extends Controller {
//    产品中心
    public function index()
    {
        $zifuji=Cookie::get('think_var');
        $chanpin =  DB::name('Goods_category')->where('parent_id',0)->where('is_show',1)->limit('1')->find();
        $erweima = DB::name('Website')->where('w_logo_status',1)->find();
        $id = input('id');
//        $list = DB::name('Goods_category')->where('parent_id',0)->where('is_show',1)->select();
        $list = Lang::get('dbcp');
        if($zifuji=='zh-cn'){
            $arr = DB::name('Goods_category')->where('parent_id',$id)->where('is_show',1)->select();
            $dangqian=DB::name('Goods_category')->where('id',$id)->value('name');
        }elseif($zifuji=='en-us'){
            $arr = DB::name('Goods_category_us')->where('parent_id',$id)->where('is_show',1)->select();
            $dangqian=DB::name('Goods_category_us')->where('id',$id)->value('name');
        }else{
            $arr = DB::name('Goods_category_jp')->where('parent_id',$id)->where('is_show',1)->select();
            $dangqian=DB::name('Goods_category_jp')->where('id',$id)->value('name');
        }
        $lists = DB::name('Website')->find();
//        $lisst = DB::name('Goods_category')->where('parent_id',0)->where('is_show',1)->select();
        $lisst = Lang::get('dbcp');
        $cpzxtp=DB::name('Config')->where('name','cpzxtp')->value('value');
        $this->assign('id',$id);
        $this->assign('dangqian',$dangqian);
        $this->assign('cpzxtp',$cpzxtp);
        $this->assign('lisst',$lisst);
        $this->assign('lists',$lists);
        $this->assign('list',$list);
        $this->assign('arr',$arr);
        $this->assign('erweima',$erweima);
        $this->assign('chanpin',$chanpin);
        return $this->fetch('cp/cp');
    }
    
    public function cpxx()
    {
        $zifuji=Cookie::get('think_var');
        $chanpin =  DB::name('Goods_category')->where('parent_id',0)->where('is_show',1)->limit('1')->find();
        $erweima = DB::name('Website')->where('w_logo_status',1)->find();
//        $list = DB::name('Goods_category')->where('parent_id',0)->where('is_show',1)->select();
        $list = Lang::get('dbcp');
        $id = input('id');
        if($zifuji=='zh-cn'){
            $li = DB::name('Case_type')->where('ct_gid',$id)->where('status','1')->select();
        }elseif($zifuji=='en-us'){
            $li = DB::name('Case_type_us')->where('ct_gid',$id)->where('status','1')->select();
        }else{
            $li = DB::name('Case_type_jp')->where('ct_gid',$id)->where('status','1')->select();
        }

        $lists = DB::name('Website')->find();
//        $lisst = DB::name('Goods_category')->where('parent_id',0)->where('is_show',1)->select();
        $lisst = Lang::get('dbcp');
        $cpzxtp=DB::name('Config')->where('name','cpzxtp')->value('value');
        $this->assign('cpzxtp',$cpzxtp);
        $this->assign('lisst',$lisst);
        $this->assign('lists',$lists);
        $this->assign('list',$list);
        $this->assign('li',$li);
        $this->assign('erweima',$erweima);
        $this->assign('chanpin',$chanpin);
        $this->assign('chanpin',$chanpin);
        return $this->fetch('cp/cpxx');
    }
    public function cp()
    {
        $zifuji=Cookie::get('think_var');
        $chanpin =  DB::name('Goods_category')->where('parent_id',0)->where('is_show',1)->limit('1')->find();
        $erweima = DB::name('Website')->where('w_logo_status',1)->find();
//        $list = DB::name('Goods_category')->where('parent_id',0)->where('is_show',1)->select();
        $list = Lang::get('dbcp');
        $id = input('id');
//        dump($id);die();
        if($zifuji=='zh-cn'){
            $li = DB::name('Case_type')->where('ct_gid',$id)->find();
        }elseif($zifuji=='en-us'){
            $li = DB::name('Case_type_us')->where('ct_gid',$id)->find();
        }else{
            $li = DB::name('Case_type_jp')->where('ct_gid',$id)->find();
        }
        $li['ct_jianjie'] = htmlspecialchars_decode($li['ct_jianjie']);
        $lists = DB::name('Website')->find();
        $lisst = Lang::get('dbcp');
        $cpzxtp=DB::name('Config')->where('name','cpzxtp')->value('value');
        $this->assign('cpzxtp',$cpzxtp);
        $this->assign('lisst',$lisst);
//        dump($lists);die();
        $this->assign('lists',$lists);
        $this->assign('list',$list);
        $this->assign('li',$li);
        $this->assign('erweima',$erweima);
        $this->assign('chanpin',$chanpin);
        return $this->fetch('cp/cc');
    }
    /**
     * 产品搜索
     */
    public function search()
    {

        $chanpin =  DB::name('Goods_category')->where('parent_id',0)->where('is_show',1)->limit('1')->find();
        $erweima = DB::name('Website')->where('w_logo_status',1)->find();
        $list = Lang::get('dbcp');
        $lists = DB::name('Website')->find();
        $lisst = Lang::get('dbcp');

        $xiangqing=DB::name('Details')->select();

        $arr=array();
        foreach($xiangqing as $key=>$val){
            if(!in_array($xiangqing[$key]['p_p_type'],$arr)){
                if($xiangqing[$key]['p_p_type']!=null){
                    array_push($arr,$xiangqing[$key]['p_p_type']);
                }
            }
        }

        $arr1=array();
        foreach($xiangqing as $key=>$val){
            if(!in_array($xiangqing[$key]['p_application'],$arr1)){
                if($xiangqing[$key]['p_application']!=null){
                    array_push($arr1,$xiangqing[$key]['p_application']);
                }
            }
        }

        $arr2=array();
        foreach($xiangqing as $key=>$val){
            if(!in_array($xiangqing[$key]['p_displacement'],$arr2)){
                if($xiangqing[$key]['p_displacement']!=null){
                    array_push($arr2,$xiangqing[$key]['p_displacement']);
                    sort($arr2);
                }
            }
        }

        $arr3=array();
        foreach($xiangqing as $key=>$val){
            if(!in_array($xiangqing[$key]['p_cryogen'],$arr3)){
                if($xiangqing[$key]['p_cryogen']!=null){
                    array_push($arr3,$xiangqing[$key]['p_cryogen']);
                }
            }
        }

        $arr4=array();
        foreach($xiangqing as $key=>$val){
            if(!in_array($xiangqing[$key]['p_form'],$arr4)){
                if($xiangqing[$key]['p_form']!=null){
                    array_push($arr4,$xiangqing[$key]['p_form']);
                }
            }
        }

        $cpzxtp=DB::name('Config')->where('name','cpzxtp')->value('value');
        $this->assign('cpzxtp',$cpzxtp);

//        dump($arr);die();/
        $this->assign('arr',$arr);
        $this->assign('arr1',$arr1);
        $this->assign('arr2',$arr2);
        $this->assign('arr3',$arr3);
        $this->assign('arr4',$arr4);
        $this->assign('lisst',$lisst);
        $this->assign('lists',$lists);
        $this->assign('list',$list);
        $this->assign('erweima',$erweima);
        $this->assign('chanpin',$chanpin);
        return $this->fetch('cp/search');
    }

    public function sousuo(){
        header("content-type:text/html;charset=utf-8");
        $zifuji=Cookie::get('think_var');
        $dianyuan=input('dianyuan');
        $yingyong=input('yingyong');
        $pailiang=input('pailiang');
        $zhileng=input('zhileng');
        $xingshi=input('xingshi');
//        dump($dianyuan);
//        dump($yingyong);
//        dump($pailiang);
//        dump($zhileng);
//        dump($xingshi);die();
        if(!empty($dianyuan)){
            $where['p_p_type']=$dianyuan;
        }
        if(!empty($yingyong)){
            $where['p_application']=$yingyong;
        }
        if(!empty($zhileng)){
            $where['p_cryogen']=$zhileng;
        }
        if(!empty($pailiang)){
            $where['p_displacement']=$pailiang;
        }

        if(!empty($xingshi)){
            $where['p_form']=$xingshi;
        }
//        dump($where);
        $cpxq=DB::name('Details')->where($where)->select();
//        dump($cpxq);die();
        $chanpin =  DB::name('Goods_category')->where('parent_id',0)->where('is_show',1)->limit('1')->find();
        $erweima = DB::name('Website')->where('w_logo_status',1)->find();
        $list = Lang::get('dbcp');
        $lists = DB::name('Website')->find();
        $lisst = Lang::get('dbcp');
        $cpzxtp=DB::name('Config')->where('name','cpzxtp')->value('value');
        $this->assign('cpzxtp',$cpzxtp);
        $this->assign('cpxq',$cpxq);
        $this->assign('lisst',$lisst);
        $this->assign('lists',$lists);
        $this->assign('list',$list);
        $this->assign('erweima',$erweima);
        $this->assign('chanpin',$chanpin);
        return $this->fetch('cp/sousuo');
    }

    public function shaixuan(){
        $dianyuan=input('dianyuan');
        $zhileng=input('zhileng');
        $yingyong=input('yingyong');
        if($zhileng!=null){
            $where['p_cryogen']=$zhileng;
        }
        if($yingyong!=null){
            $where1['p_application']=$yingyong;
        }
        if($dianyuan!=null){
            $xiangqing=DB::name('Details')->where('p_p_type',$dianyuan)->where($where)->where($where1)->select();
            $arr1=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_application'],$arr1)){
                    if($xiangqing[$key]['p_application']!=null){
                        array_push($arr1,$xiangqing[$key]['p_application']);
                    }
                }
            }
        }else{
            $xiangqing=DB::name('Details')->where($where)->where($where1)->select();
            $arr1=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_application'],$arr1)){
                    if($xiangqing[$key]['p_application']!=null){
                        array_push($arr1,$xiangqing[$key]['p_application']);
                    }
                }
            }
        }

        return json($arr1);
    }

    public function shaixuan1(){
        $dianyuan=input('dianyuan');
        $zhileng=input('zhileng');
        $yingyong=input('yingyong');
        if($zhileng!=null){
            $where['p_cryogen']=$zhileng;
        }
        if($yingyong!=null){
            $where1['p_application']=$yingyong;
        }
        if($dianyuan!=null){
            $xiangqing=DB::name('Details')->where('p_p_type',$dianyuan)->where($where)->where($where1)->select();
            $arr2=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_displacement'],$arr2)){
                    if($xiangqing[$key]['p_displacement']!=null){
                        array_push($arr2,$xiangqing[$key]['p_displacement']);
                        sort($arr2);
                    }
                }
            }
        }else{
            $xiangqing=DB::name('Details')->where($where)->where($where1)->select();
            $arr2=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_displacement'],$arr2)){
                    if($xiangqing[$key]['p_displacement']!=null){
                        array_push($arr2,$xiangqing[$key]['p_displacement']);
                        sort($arr2);
                    }
                }
            }
        }

        return json($arr2);
    }

    public function shaixuan2(){
        $dianyuan=input('dianyuan');
        $zhileng=input('zhileng');
        $yingyong=input('yingyong');
        if($zhileng!=null){
            $where['p_cryogen']=$zhileng;
        }
        if($yingyong!=null){
            $where1['p_application']=$yingyong;
        }
        if($dianyuan!=null){
            $xiangqing=DB::name('Details')->where('p_p_type',$dianyuan)->where($where)->where($where1)->select();
            $arr3=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_cryogen'],$arr3)){
                    if($xiangqing[$key]['p_cryogen']!=null){
                        array_push($arr3,$xiangqing[$key]['p_cryogen']);
                    }
                }
            }
        }else{
            $xiangqing=DB::name('Details')->where($where)->where($where1)->select();
            $arr3=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_cryogen'],$arr3)){
                    if($xiangqing[$key]['p_cryogen']!=null){
                        array_push($arr3,$xiangqing[$key]['p_cryogen']);
                    }
                }
            }
        }



        return json($arr3);
    }

    public function shaixuan3(){
        $dianyuan=input('dianyuan');
        $zhileng=input('zhileng');
        $yingyong=input('yingyong');
        if($zhileng!=null){
            $where['p_cryogen']=$zhileng;
        }
        if($yingyong!=null){
            $where1['p_application']=$yingyong;
        }
        if($dianyuan!=null){
            $xiangqing=DB::name('Details')->where('p_p_type',$dianyuan)->where($where)->where($where1)->select();
            $arr4=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_form'],$arr4)){
                    if($xiangqing[$key]['p_form']!=null){
                        array_push($arr4,$xiangqing[$key]['p_form']);
                    }
                }
            }
        }else{
            $xiangqing=DB::name('Details')->where($where)->where($where1)->select();
            $arr4=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_form'],$arr4)){
                    if($xiangqing[$key]['p_form']!=null){
                        array_push($arr4,$xiangqing[$key]['p_form']);
                    }
                }
            }
        }

        return json($arr4);
    }

    public function shaixuanzl(){
        $zhileng=input('zhileng');
        $dianyuan=input('dianyuan');
        $yingyong=input('yingyong');
        if($dianyuan!=null){
            $where['p_p_type']=$dianyuan;
        }
        if($yingyong!=null){
            $where1['p_application']=$yingyong;
        }
        if($zhileng!=null){
            $xiangqing=DB::name('Details')->where('p_cryogen',$zhileng)->where($where)->where($where1)->select();
            $arr1=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_application'],$arr1)){
                    if($xiangqing[$key]['p_application']!=null){
                        array_push($arr1,$xiangqing[$key]['p_application']);
                    }
                }
            }
        }else{
            $xiangqing=DB::name('Details')->where($where)->where($where1)->select();
            $arr1=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_application'],$arr1)){
                    if($xiangqing[$key]['p_application']!=null){
                        array_push($arr1,$xiangqing[$key]['p_application']);
                    }
                }
            }
        }

        return json($arr1);
    }

    public function shaixuanzl1(){
        $zhileng=input('zhileng');
        $dianyuan=input('dianyuan');
        $yingyong=input('yingyong');
        if($dianyuan!=null){
            $where['p_p_type']=$dianyuan;
        }
        if($yingyong!=null){
            $where1['p_application']=$yingyong;
        }
        if($zhileng!=null){
            $xiangqing=DB::name('Details')->where('p_cryogen',$zhileng)->where($where)->where($where1)->select();
            $arr2=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_displacement'],$arr2)){
                    if($xiangqing[$key]['p_displacement']!=null){
                        array_push($arr2,$xiangqing[$key]['p_displacement']);
                        sort($arr2);
                    }
                }
            }
        }else{
            $xiangqing=DB::name('Details')->where($where)->where($where1)->select();
            $arr2=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_displacement'],$arr2)){
                    if($xiangqing[$key]['p_displacement']!=null){
                        array_push($arr2,$xiangqing[$key]['p_displacement']);
                        sort($arr2);
                    }
                }
            }
        }

        return json($arr2);
    }

    public function shaixuanzl2(){
        $zhileng=input('zhileng');
        $dianyuan=input('dianyuan');
        $yingyong=input('yingyong');
        if($dianyuan!=null){
            $where['p_p_type']=$dianyuan;
        }
        if($yingyong!=null){
            $where1['p_application']=$yingyong;
        }
        if($zhileng!=null){
            $xiangqing=DB::name('Details')->where('p_cryogen',$zhileng)->where($where)->where($where1)->select();
            $arr3=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_p_type'],$arr3)){
                    if($xiangqing[$key]['p_p_type']!=null){
                        array_push($arr3,$xiangqing[$key]['p_p_type']);
                    }
                }
            }
        }else{
            $xiangqing=DB::name('Details')->where($where)->where($where1)->select();
            $arr3=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_p_type'],$arr3)){
                    if($xiangqing[$key]['p_p_type']!=null){
                        array_push($arr3,$xiangqing[$key]['p_p_type']);
                    }
                }
            }
        }



        return json($arr3);
    }

    public function shaixuanzl3(){
        $zhileng=input('zhileng');
        $dianyuan=input('dianyuan');
        $yingyong=input('yingyong');
        if($dianyuan!=null){
            $where['p_p_type']=$dianyuan;
        }
        if($yingyong!=null){
            $where1['p_application']=$yingyong;
        }
        if($zhileng!=null){
            $xiangqing=DB::name('Details')->where('p_cryogen',$zhileng)->where($where)->where($where1)->select();
            $arr4=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_form'],$arr4)){
                    if($xiangqing[$key]['p_form']!=null){
                        array_push($arr4,$xiangqing[$key]['p_form']);
                    }
                }
            }
        }else{
            $xiangqing=DB::name('Details')->where($where)->where($where1)->select();
            $arr4=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_form'],$arr4)){
                    if($xiangqing[$key]['p_form']!=null){
                        array_push($arr4,$xiangqing[$key]['p_form']);
                    }
                }
            }
        }

        return json($arr4);
    }

    public function shaixuanyy(){
        $yingyong=input('yingyong');
        $dianyuan=input('dianyuan');
        $zhileng=input('zhileng');
        if($dianyuan!=null){
            $where['p_p_type']=$dianyuan;
        }
        if($zhileng!=null){
            $where1['p_cryogen']=$zhileng;
        }
        if($yingyong!=null){
            $xiangqing=DB::name('Details')->where('p_application',$yingyong)->where($where)->where($where1)->select();
            $arr1=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_p_type'],$arr1)){
                    if($xiangqing[$key]['p_p_type']!=null){
                        array_push($arr1,$xiangqing[$key]['p_p_type']);
                    }
                }
            }
        }else{
            $xiangqing=DB::name('Details')->where($where)->where($where1)->select();
            $arr1=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_p_type'],$arr1)){
                    if($xiangqing[$key]['p_p_type']!=null){
                        array_push($arr1,$xiangqing[$key]['p_p_type']);
                    }
                }
            }
        }

        return json($arr1);
    }

    public function shaixuanyy1(){
        $yingyong=input('yingyong');
        $dianyuan=input('dianyuan');
        $zhileng=input('zhileng');
        if($dianyuan!=null){
            $where['p_p_type']=$dianyuan;
        }
        if($zhileng!=null){
            $where1['p_cryogen']=$zhileng;
        }
        if($yingyong!=null){
            $xiangqing=DB::name('Details')->where('p_application',$yingyong)->where($where)->where($where1)->select();
            $arr2=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_displacement'],$arr2)){
                    if($xiangqing[$key]['p_displacement']!=null){
                        array_push($arr2,$xiangqing[$key]['p_displacement']);
                        sort($arr2);
                    }
                }
            }
        }else{
            $xiangqing=DB::name('Details')->where($where)->where($where1)->select();
            $arr2=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_displacement'],$arr2)){
                    if($xiangqing[$key]['p_displacement']!=null){
                        array_push($arr2,$xiangqing[$key]['p_displacement']);
                        sort($arr2);
                    }
                }
            }
        }

        return json($arr2);
    }

    public function shaixuanyy2(){
        $yingyong=input('yingyong');
        $dianyuan=input('dianyuan');
        $zhileng=input('zhileng');
        if($dianyuan!=null){
            $where['p_p_type']=$dianyuan;
        }
        if($zhileng!=null){
            $where1['p_cryogen']=$zhileng;
        }
        if($yingyong!=null){
            $xiangqing=DB::name('Details')->where('p_application',$yingyong)->where($where)->where($where1)->select();
            $arr3=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_cryogen'],$arr3)){
                    if($xiangqing[$key]['p_cryogen']!=null){
                        array_push($arr3,$xiangqing[$key]['p_cryogen']);
                    }
                }
            }
        }else{
            $xiangqing=DB::name('Details')->where($where)->where($where1)->select();
            $arr3=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_cryogen'],$arr3)){
                    if($xiangqing[$key]['p_cryogen']!=null){
                        array_push($arr3,$xiangqing[$key]['p_cryogen']);
                    }
                }
            }
        }



        return json($arr3);
    }

    public function shaixuanyy3(){
        $yingyong=input('yingyong');
        $dianyuan=input('dianyuan');
        $zhileng=input('zhileng');
        if($dianyuan!=null){
            $where['p_p_type']=$dianyuan;
        }
        if($zhileng!=null){
            $where1['p_cryogen']=$zhileng;
        }
        if($yingyong!=null){
            $xiangqing=DB::name('Details')->where('p_application',$yingyong)->where($where)->where($where1)->select();
            $arr4=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_form'],$arr4)){
                    if($xiangqing[$key]['p_form']!=null){
                        array_push($arr4,$xiangqing[$key]['p_form']);
                    }
                }
            }
        }else{
            $xiangqing=DB::name('Details')->where($where)->where($where1)->select();
            $arr4=array();
            foreach($xiangqing as $key=>$val){
                if(!in_array($xiangqing[$key]['p_form'],$arr4)){
                    if($xiangqing[$key]['p_form']!=null){
                        array_push($arr4,$xiangqing[$key]['p_form']);
                    }
                }
            }
        }

        return json($arr4);
    }
}